﻿using System;
using System.Xml;
using System.Threading;

using Microsoft.BizTalk.Component.Interop;
using Microsoft.BizTalk.TransportProxy.Interop;
using Microsoft.BizTalk.Message.Interop;

using Microsoft.Samples.BizTalk.Adapter.Common;

namespace Sixeyed.CacheAdapter.Runtime
{
    /// <summary>
    /// Batch transmitter for cache sends
    /// </summary>
    sealed public class CacheTransmitter : AsyncTransmitter
    {
        private static string CacheNamespace = "http://schemas.sixeyed.com/CacheAdapter/2009";

        public CacheTransmitter() : base(
                "Cache Transmit Adapter",
                "1.0",
                "Submits a request for an object to the cache provider",
                "Cache",
                new Guid("dbe8615d-547a-4c76-8793-da0a1728200d"),
                CacheNamespace, 
                typeof(CacheTransmitterEndpoint), 
				10)
        {
        }

		protected override IBTTransmitterBatch CreateAsyncTransmitterBatch()
		{
			return new CacheTransmitAdapterBatch(this.MaxBatchSize, CacheNamespace, TransportProxy, this);		
		}

        public ConfigProperties CreateProperties(string uri)
        {
            ConfigProperties properties = new CacheTransmitProperties(uri);
            return properties;
        }

        protected override void HandlerPropertyBagLoaded()
        {
            IPropertyBag config = this.HandlerPropertyBag;
            if (null != config)
            {
                XmlDocument handlerConfigDom = ConfigProperties.IfExistsExtractConfigDom(config);
                if (null != handlerConfigDom)
                {
                    CacheTransmitProperties.TransmitHandlerConfiguration(handlerConfigDom);
                }
            }
        }
    }
}
